//Stephen Erb Application GUI

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.GridLayout;


public class Choose extends JFrame implements ActionListener{
	String choice;
    ButtonGroup group;
    JButton selection;
    JRadioButton personButton;  
    JRadioButton studentButton; 
    JRadioButton employeeButton;
    JRadioButton healthcareButton;
    JRadioButton exitButton; 
	public Choose()
	{
            setLayout(new GridLayout(8, 2, 5, 5));
	    JRadioButton personButton = new JRadioButton("Person");
	    personButton.setMnemonic(KeyEvent.VK_B);
	    personButton.setActionCommand("PERSON");
	    personButton.setSelected(true);

	    JRadioButton studentButton = new JRadioButton("Student");
	    studentButton.setMnemonic(KeyEvent.VK_C);
	    studentButton.setActionCommand("STUDENT");

	    JRadioButton employeeButton = new JRadioButton("Employee");
	    employeeButton.setMnemonic(KeyEvent.VK_D);
	    employeeButton.setActionCommand("EMPLOYEE");
            
	    JRadioButton healthcareButton = new JRadioButton("HealthCare");
	    healthcareButton.setMnemonic(KeyEvent.VK_D);
	    healthcareButton.setActionCommand("HEALTHCARE");
            
	    JRadioButton businessButton = new JRadioButton("Business Owner");
	    businessButton.setMnemonic(KeyEvent.VK_D);
	    businessButton.setActionCommand("BUSINESS");
            
	    JRadioButton languageButton = new JRadioButton("Language");
	    languageButton.setMnemonic(KeyEvent.VK_D);
	    languageButton.setActionCommand("LANGUAGE");
            
	    JRadioButton exitButton = new JRadioButton("Exit");
	    exitButton.setMnemonic(KeyEvent.VK_R);
	    exitButton.setActionCommand("EXIT");

	    //Group the radio buttons.
	    group = new ButtonGroup();
	    group.add(personButton);
	    group.add(studentButton);
	    group.add(employeeButton);
            group.add(healthcareButton);
            group.add(businessButton);
            group.add(languageButton);
	    group.add(exitButton);

	    //Register a listener for the radio buttons.
	    personButton.addActionListener(this);
	    studentButton.addActionListener(this);
	    employeeButton.addActionListener(this);
            healthcareButton.addActionListener(this);
            businessButton.addActionListener(this);
            languageButton.addActionListener(this);
	    exitButton.addActionListener(this);
	    
	    selection=new JButton("Selection");
		selection.setActionCommand("SELECTED");
	    selection.addActionListener(this);
	    add(personButton);
	    add(studentButton);
	    add(employeeButton);
            add(healthcareButton);
            add(businessButton);
            add(languageButton);
	    add(exitButton);
	    add(selection);
	}
	public void initialize()
	{
		this.setTitle("Choose");
		this.setSize(400,300);
		this.setLocationRelativeTo(null);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
	public void actionPerformed(ActionEvent event)
	{
		String command=event.getActionCommand();
		if(command=="SELECTED")
		{       
			if(group.getSelection().getActionCommand()=="PERSON")
			{
			    Person p1;
			    try {
			            p1 = new Person();
			            p1.initialize();
                                    dispose();
			    } catch (Exception e) {
			            // TODO Auto-generated catch block
			            e.printStackTrace();
			    }
			}
			else if(group.getSelection().getActionCommand()=="STUDENT")
			{
                            Student s1;
			    try {
			            s1 = new Student();
			            s1.initialize();
                                    dispose();
			    } catch (Exception e) {
			            // TODO Auto-generated catch block
			            e.printStackTrace();
			    }
			}
			else if(group.getSelection().getActionCommand()=="EMPLOYEE")
			{
			    Employee e1;
			    try {
			            e1 = new Employee();
			            e1.initialize();
			            dispose();
			    } catch (Exception e) {
			            // TODO Auto-generated catch block
			            e.printStackTrace();
			    }
			}
                        else if(group.getSelection().getActionCommand()=="HEALTHCARE")
                        {
                            HealthCare h1;
                            try {
                                    h1 = new HealthCare();
                                    h1.initialize();
                                    //dispose();
                            } catch (Exception e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                            }
                        }
                        else if(group.getSelection().getActionCommand()=="BUSINESS")
                        {
                            BusinessOwner b1;
                            try {
                                    b1 = new BusinessOwner();
                                    b1.initialize();
                                    //dispose();
                            } catch (Exception e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                            }
                        }
                        else if(group.getSelection().getActionCommand()=="LANGUAGE")
                        {
                            Language l1;
                            try {
                                    l1 = new Language();
                                    l1.initialize();
                                    //dispose();
                            } catch (Exception e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                            }
                        }
			else System.exit(0);
		}
	}
}

